package org.hackystat.linkedservicedata.ui.projects;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import org.hackystat.linkedservicedata.sparql.SparqlFilter;
import org.hackystat.linkedservicedata.ui.LinkedServiceDataUI;
import org.hackystat.linkedservicedata.vocabularies.HackystatConstants;
import com.hp.hpl.jena.ontology.OntProperty;
import org.hackystat.linkedservicedata.vocabularies.DoapVocab;

/**
 * Project search wizard panel.
 *
 * @author Myriam Leggieri.
 *
 */
public class ProjectSearchWizard extends JFrame implements ItemListener, ActionListener {
  /**
   *
   */
  private static final long serialVersionUID = -350410153890069549L;

  /** Parent frame. */
  LinkedServiceDataUI mainframe = null;

  /** Wiki text area. */
  private JTextArea descriptionArea = null;

  /** Project owner's email label. */
  public JLabel ownerLabel = null;

  /** Start date label. */
  public JLabel startDateLabel = null;

  /** End date label. */
  public JLabel endDateLabel = null;

  /** Visibility label. */
  public JLabel visibilityLabel = null;

  /** Project name label. */
  public JLabel projnameLabel = null;

  /** Last modification date label. */
  public JLabel modifiedDateLabel = null;

  /** Anonymous repository label. */
  public JLabel repAnonLabel = null;

  /** Repository label. */
  public JLabel repLabel = null;

  /** Repository web browser interface label. */
  public JLabel repWebLabel = null;

  /** Bug DBs label. */
  public JLabel bugDbsLabel = null;

  /** Operating systems label. */
  public JLabel osystemsLabel = null;

  /** Description label. */
  public JLabel descriptionLabel = null;

  /** Visibility text. */
  public JTextField ownerText = null;

  /** Name text. */
  public JTextField visibilityText = null;

  /** Creation date text. */
  public JFormattedTextField startDateText = null;

  /** Closure date text. */
  public JFormattedTextField endDateText = null;

  /** Last modification date text. */
  public JFormattedTextField modifiedDateText = null;

  /** Anonymous repository text. */
  public JTextField repAnonText = null;

  /** Email text. */
  public JTextField projnameText = null;

  /** Repository text. */
  public JTextField repText = null;

  /** Repository Web browser interface text. */
  public JTextField repWebText = null;

  /** SeeAlso URI container. */
  public String[] seeAlso = null;

  /** SeeAlso URI JList. */
  public JList seeAlsoList = null;

  /** SeeAlso 'add' button. */
  public JButton seeAlsoButton = null;

  /** Search button. */
  public JButton searchButton = null;

  /** Cancel button. */
  public JButton cancelButton = null;

  /** SeeAlso label. */
  public JLabel seeAlsoLabel = null;

  /** SeeAlso text field. */
  public JTextField seeAlsoText = null;

  /** SameAs label. */
  public JLabel sameAsLabel = null;

  /** SameAs URI container. */
  public String[] sameAs = null;

  /** SameAs URI JList. */
  public JList sameAsList = null;

  /** SameAs 'add' button. */
  public JButton sameAsButton = null;

  /** SameAs text field. */
  public JTextField sameAsText = null;

  /** Roles combo label. */
  private JLabel rolesComboLabel = null;

  /** Roles combo. */
  private JComboBox rolesCombo = null;

  /** Members/Role list label. */
  private JLabel membersRoleListLabel = null;

  /** Member value label. */
  private JLabel membersRoleValueLabel = null;

  /** Member value text. */
  private JTextField membersRoleValueText = null;

  /** Members/Role jlist. */
  private JList membersRoleList = null;

  /** Add duplicates button. */
  private JButton addMembersRoleButton = null;

  /** Remove sameAs button. */
  private JButton removeMembersRoleButton = null;

  /** Tags label. */
  private JLabel toolsLabel = null;

  /** Tags value label. */
  private JLabel toolsValueLabel = null;

  /** Tags text. */
  private JTextField toolsValueText = null;

  /** Tools jlist. */
  private JList toolsList = null;

  /** Add tags button. */
  private JButton addToolsButton = null;

  /** Remove tags button. */
  private JButton removeToolsButton = null;

  /** Tags label. */
  private JLabel invitatesLabel = null;

  /** Tags value label. */
  private JLabel invitatesValueLabel = null;

  /** Tags text. */
  private JTextField invitatesValueText = null;

  /** Tools jlist. */
  private JList invitatesList = null;

  /** Add tags button. */
  private JButton addInvitatesButton = null;

  /** Remove tags button. */
  private JButton removeInvitatesButton = null;

  /** Tags label. */
  private JLabel membersLabel = null;

  /** Tags value label. */
  private JLabel membersValueLabel = null;

  /** Tags text. */
  private JTextField membersValueText = null;

  /** Tools jlist. */
  private JList membersList = null;

  /** Add tags button. */
  private JButton addMemebersButton = null;

  /** Remove tags button. */
  private JButton removeMemebersButton = null;

  /** Tags label. */
  private JLabel spectatorsLabel = null;

  /** Tags value label. */
  private JLabel spectatorsValueLabel = null;

  /** Tags text. */
  private JTextField spectatorsValueText = null;

  /** Tools jlist. */
  private JList spectatorsList = null;

  /** Add tags button. */
  private JButton addSpectatorsButton = null;

  /** Remove tags button. */
  private JButton removeSpectatorsButton = null;

  /** Dev phase label. */
  private JLabel devPhaseLabel = null;

  /** Tags value label. */
  private JLabel devPhaseValueLabel = null;

  /** Tags text. */
  private JTextField devPhaseValueText = null;

  /** Dev phases jlist. */
  private JList devPhasesList = null;

  /** Add tags button. */
  private JButton addDevPhaseButton = null;

  /** Remove tags button. */
  private JButton removeDevPhaseButton = null;

  /** Tags label. */
  private JLabel tagsLabel = null;

  /** Tags value label. */
  private JLabel tagsValueLabel = null;

  /** Tags text. */
  private JTextField tagsValueText = null;

  /** Tags jlist. */
  private JList tagsList = null;

  /** Add tags button. */
  private JButton addTagsButton = null;

  /** Remove tags button. */
  private JButton removeTagsButton = null;

  /** Tags label. */
  private JLabel wikisLabel = null;

  /** Tags value label. */
  private JLabel wikisValueLabel = null;

  /** Tags text. */
  private JTextField wikisValueText = null;

  /** Tags jlist. */
  private JList wikisList = null;

  /** Add tags button. */
  private JButton addWikisButton = null;

  /** Remove tags button. */
  private JButton removeWikisButton = null;

  /** Tags label. */
  private JLabel progrLangsLabel = null;

  /** Tags value label. */
  private JLabel progrLangsValueLabel = null;

  /** Tags text. */
  private JTextField progrLangsValueText = null;

  /** Tags jlist. */
  private JList progrLangsList = null;

  /** Add tags button. */
  private JButton addProgrLangsButton = null;

  /** Remove tags button. */
  private JButton removeProgrLangsButton = null;

  /** Tags label. */
  private JLabel osystemLabel = null;

  /** Tags value label. */
  private JLabel osystemValueLabel = null;

  /** Tags text. */
  private JTextField osystemValueText = null;

  /** Tags jlist. */
  private JList osystemList = null;

  /** Add tags button. */
  private JButton addOsystemButton = null;

  /** Remove tags button. */
  private JButton removeOsystemButton = null;

  /** Tags label. */
  private JLabel mirrorsLabel = null;

  /** Tags value label. */
  private JLabel mirrorsValueLabel = null;

  /** Tags text. */
  private JTextField mirrorsValueText = null;

  /** Tags jlist. */
  private JList mirrorsList = null;

  /** Add tags button. */
  private JButton addMirrorsButton = null;

  /** Remove tags button. */
  private JButton removeMirrorsButton = null;

  /** Tags label. */
  private JLabel bugdbLabel = null;

  /** Tags value label. */
  private JLabel bugdbValueLabel = null;

  /** Tags text. */
  private JTextField bugdbValueText = null;

  /** Tags jlist. */
  private JList bugdbList = null;

  /** Add tags button. */
  private JButton addBugdbButton = null;

  /** Remove tags button. */
  private JButton removeBugdbButton = null;

  /** Sparql filters container. */
  public LinkedList<SparqlFilter> filtersList = null;

  /** Filter value text. */
  private JTextField filterValueText = null;

  /** Skills combo box. */
  private JComboBox skillsCombo = null;

  /** Skills label. */
  private JLabel filterValueLabel = null;

  /** Skills label. */
  private JLabel skillsLabel = null;

  /** Skills list label. */
  private JLabel skillsListLabel = null;

  /** SameAs list label. */
  private JLabel sameAsListLabel = null;

  /** SeeAlso list label. */
  private JLabel seeAlsoListLabel = null;

  /** JList of selected skills and values. */
  private JList skillsValueList = null;

  /** Add filter button. */
  private JButton addFilterButton = null;

  /** Remove filter button. */
  private JButton removeFilterButton = null;

  /** Add sameAs button. */
  private JButton addSameAsButton = null;

  /** Remove sameAs button. */
  private JButton removeSameAsButton = null;

  /** Add seeAlso button. */
  private JButton addSeeAlsoButton = null;

  /** Remove seeAlso button. */
  private JButton removeSeeAlsoButton = null;

  /** Greater Than check box. */
  private JCheckBox greaterThanCheckBox = null;

  /** Less Than check box. */
  private JCheckBox lessThanCheckBox = null;

  /** Equals to check box. */
  private JCheckBox equalsToCheckBox = null;

  /** Main container. */
  private Container container = null;

  public ProjectSearchWizard(LinkedServiceDataUI parent) {
    super("Hackystat - Search for projects");
    mainframe = parent;
    container = this.getContentPane();
    refresh(true);
    pack();
    setSize(mainframe.popUpWinDimension);
    setLocationRelativeTo(null);
    setBackground(Color.white);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        setVisible(false);
        dispose();
      }
    });
    setVisible(true);
  }

  public void refresh(boolean reset) {
    container.removeAll();
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBackground(Color.WHITE);
    if (mainframe.isLogged()) {
      initLabelHeaders1();
      initJTextFields(reset);
      initJLists();
      panel.add(fillInUserProfileData1());
      panel.add(Box.createVerticalGlue());
      panel.add(fillInUserProfileData2());
      panel.add(Box.createVerticalGlue());
      panel.add(fillInUserProfileData3());
      panel.add(Box.createVerticalGlue());
      panel.add(fillInProjectSkills());
      panel.add(getActions());
    }
    panel.setBackground(Color.white);
    JScrollPane listScrollPane = new JScrollPane(panel);
    listScrollPane.setPreferredSize(mainframe.popUpWinDimension);
    listScrollPane.setMaximumSize(mainframe.popUpWinDimension);
    listScrollPane.setMinimumSize(mainframe.popUpWinDimension);
    container.add(listScrollPane);
    container.validate();
  }

  private void initJTextFields(boolean reset) {
    String empty = "";
    if (projnameText == null || reset) {
      projnameText = new JTextField(10);
      projnameText = mainframe.initTextField(projnameText, empty, true);
    }
    if (repAnonText == null || reset) {
      repAnonText = new JTextField(10);
      repAnonText = mainframe.initTextField(repAnonText, empty, true);
    }
    if (repText == null || reset) {
      repText = new JTextField(10);
      repText = mainframe.initTextField(repText, empty, true);
    }
    if (repWebText == null || reset) {
      repWebText = new JTextField(10);
      repWebText = mainframe.initTextField(repWebText, empty, true);
    }
    if (visibilityText == null || reset) {
      visibilityText = new JTextField(10);
      visibilityText = mainframe.initTextField(visibilityText, empty, true);
    }
    if (ownerText == null || reset) {
      ownerText = new JTextField(10);
      ownerText = mainframe.initTextField(ownerText, empty, true);
    }
    String tooltip = "Use the date format 'yyyy-M-d' please";
    if (startDateText == null || reset) {
      startDateText = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d"));
      startDateText = mainframe.initFormattedDateTextField(startDateText, "", true, tooltip);
    }
    if (endDateText == null || reset) {
      endDateText = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d"));
      endDateText = mainframe.initFormattedDateTextField(endDateText, "", true, tooltip);
    }
    if (modifiedDateText == null || reset) {
      modifiedDateText = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d"));
      modifiedDateText = mainframe
          .initFormattedDateTextField(modifiedDateText, "", true, tooltip);
    }
    if (filterValueText == null || reset) {
      filterValueText = new JTextField(10);
      filterValueText = mainframe.initTextField(filterValueText, empty, true);
    }
    if (seeAlsoText == null || reset) {
      seeAlsoText = new JTextField(10);
      seeAlsoText = mainframe.initTextField(seeAlsoText, empty, true);
    }
    if (sameAsText == null || reset) {
      sameAsText = new JTextField(10);
      sameAsText = mainframe.initTextField(sameAsText, empty, true);
    }
    return;
  }

  private JPanel fillInUserProfileData3() {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.setBackground(Color.white);
    JPanel vertic = null;

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    JScrollPane listScrollPane = new JScrollPane(wikisList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addWikisButton == null) {
      addWikisButton = new JButton("Add >>");
      addWikisButton = mainframe.initButton(addWikisButton, this, mainframe.buttonDimension,
          "Add the inserted wiki uri " + "to the list");
    }
    if (removeWikisButton == null) {
      removeWikisButton = new JButton("Remove <<");
      removeWikisButton = mainframe.initButton(removeWikisButton, this, mainframe.buttonDimension,
          "Remove the inserted wiki uri " + "to the " + "list");
    }
    wikisValueText = new JTextField(10);
    wikisValueText = mainframe.initTextField(wikisValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(wikisValueLabel, wikisValueText, addWikisButton,
        removeWikisButton, wikisLabel, listScrollPane, ""));

    listScrollPane = new JScrollPane(progrLangsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addProgrLangsButton == null) {
      addProgrLangsButton = new JButton("Add >>");
      addProgrLangsButton = mainframe.initButton(addProgrLangsButton, this,
          mainframe.buttonDimension, "Add the inserted programming " + "language to the " + "list");
    }
    if (removeProgrLangsButton == null) {
      removeProgrLangsButton = new JButton("Remove <<");
      removeProgrLangsButton = mainframe.initButton(removeProgrLangsButton, this,
          mainframe.buttonDimension, "Remove the inserted programming " + "language from the list");
    }
    progrLangsValueText = new JTextField(10);
    progrLangsValueText = mainframe.initTextField(progrLangsValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(progrLangsValueLabel, progrLangsValueText,
        addProgrLangsButton, removeProgrLangsButton, progrLangsLabel, listScrollPane, ""));

    vertic.add(Box.createVerticalStrut(3));
    listScrollPane = new JScrollPane(mirrorsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addMirrorsButton == null) {
      addMirrorsButton = new JButton("Add >>");
      addMirrorsButton = mainframe.initButton(addMirrorsButton, this, mainframe.buttonDimension,
          "Add the inserted mirror uri to the " + "list");
    }
    if (removeMirrorsButton == null) {
      removeMirrorsButton = new JButton("Remove <<");
      removeMirrorsButton = mainframe.initButton(removeMirrorsButton, this,
          mainframe.buttonDimension, "Remove the inserted mirror uri " + "from the " + "list");
    }
    mirrorsValueText = new JTextField(10);
    mirrorsValueText = mainframe.initTextField(mirrorsValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(mirrorsValueLabel, mirrorsValueText,
        addMirrorsButton, removeMirrorsButton, mirrorsLabel, listScrollPane, ""));
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    listScrollPane = new JScrollPane(bugdbList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addBugdbButton == null) {
      addBugdbButton = new JButton("Add >>");
      addBugdbButton = mainframe.initButton(addBugdbButton, this, mainframe.buttonDimension,
          "Add the inserted Bug DB uri " + "to the list");
    }
    if (removeBugdbButton == null) {
      removeBugdbButton = new JButton("Remove <<");
      removeBugdbButton = mainframe.initButton(removeBugdbButton, this, mainframe.buttonDimension,
          "Remove the inserted Bug DB uri " + "from the " + "list");
    }
    bugdbValueText = new JTextField(10);
    bugdbValueText = mainframe.initTextField(bugdbValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(bugdbValueLabel, bugdbValueText, addBugdbButton,
        removeBugdbButton, bugdbLabel, listScrollPane, ""));

    listScrollPane = new JScrollPane(osystemList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addOsystemButton == null) {
      addOsystemButton = new JButton("Add >>");
      addOsystemButton = mainframe.initButton(addOsystemButton, this, mainframe.buttonDimension,
          "Add the inserted operating " + "system to the " + "list");
    }
    if (removeOsystemButton == null) {
      removeOsystemButton = new JButton("Remove <<");
      removeOsystemButton = mainframe.initButton(removeOsystemButton, this,
          mainframe.buttonDimension, "Remove the inserted operating " + "system from the list");
    }
    osystemValueText = new JTextField(10);
    osystemValueText = mainframe.initTextField(osystemValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(osystemValueLabel, osystemValueText,
        addOsystemButton, removeOsystemButton, osystemLabel, listScrollPane, ""));
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    listScrollPane = new JScrollPane(invitatesList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addInvitatesButton == null) {
      addInvitatesButton = new JButton("Add >>");
      addInvitatesButton = mainframe.initButton(addInvitatesButton, this,
          mainframe.buttonDimension, "Add the inserted invitate's email " + "to the list");
    }
    if (removeInvitatesButton == null) {
      removeInvitatesButton = new JButton("Remove <<");
      removeInvitatesButton = mainframe.initButton(removeInvitatesButton, this,
          mainframe.buttonDimension, "Remove the inserted invitate " + "from the " + "list");
    }
    invitatesValueText = new JTextField(10);
    invitatesValueText = mainframe.initTextField(invitatesValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(invitatesValueLabel, invitatesValueText,
        addInvitatesButton, removeInvitatesButton, invitatesLabel, listScrollPane, ""));

    listScrollPane = new JScrollPane(spectatorsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);

    if (addSpectatorsButton == null) {
      addSpectatorsButton = new JButton("Add >>");
      addSpectatorsButton = mainframe.initButton(addSpectatorsButton, this,
          mainframe.buttonDimension, "Add the inserted spectator's email to the " + "list");
    }
    if (removeSpectatorsButton == null) {
      removeSpectatorsButton = new JButton("Remove <<");
      removeSpectatorsButton = mainframe.initButton(removeTagsButton, this,
          mainframe.buttonDimension, "Remove the inserted sectator " + "from the " + "list");
    }
    spectatorsValueText = new JTextField(10);
    spectatorsValueText = mainframe.initTextField(spectatorsValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(spectatorsValueLabel, spectatorsValueText,
        addSpectatorsButton, removeSpectatorsButton, spectatorsLabel, listScrollPane, ""));

    vertic.add(Box.createVerticalStrut(3));
    listScrollPane = new JScrollPane(membersList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addMemebersButton == null) {
      addMemebersButton = new JButton("Add >>");
      addMemebersButton = mainframe.initButton(addMemebersButton, this, mainframe.buttonDimension,
          "Add the inserted member's email to the " + "list");
    }
    if (removeMemebersButton == null) {
      removeMemebersButton = new JButton("Remove <<");
      removeMemebersButton = mainframe.initButton(removeMemebersButton, this,
          mainframe.buttonDimension, "Remove the inserted member " + "to the " + "list");
    }
    membersValueText = new JTextField(10);
    membersValueText = mainframe.initTextField(membersValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(membersValueLabel, membersValueText,
        addMemebersButton, removeMemebersButton, membersLabel, listScrollPane, ""));

    horiz.add(vertic);

    return horiz;
  }

  private void initJLists() {
    sameAsList = new JList(new DefaultListModel());
    sameAsList = mainframe.initJList(sameAsList);

    seeAlsoList = new JList(new DefaultListModel());
    seeAlsoList = mainframe.initJList(seeAlsoList);

    membersRoleList = new JList(new DefaultListModel());
    membersRoleList = mainframe.initJList(membersRoleList);

    skillsValueList = new JList(new DefaultListModel());
    skillsValueList = mainframe.initJList(skillsValueList);

    devPhasesList = new JList(new DefaultListModel());
    devPhasesList = mainframe.initJList(devPhasesList);

    toolsList = new JList(new DefaultListModel());
    toolsList = mainframe.initJList(toolsList);

    tagsList = new JList(new DefaultListModel());
    tagsList = mainframe.initJList(tagsList);

    spectatorsList = new JList(new DefaultListModel());
    spectatorsList = mainframe.initJList(spectatorsList);

    membersList = new JList(new DefaultListModel());
    membersList = mainframe.initJList(membersList);

    invitatesList = new JList(new DefaultListModel());
    invitatesList = mainframe.initJList(invitatesList);

    wikisList = new JList(new DefaultListModel());
    wikisList = mainframe.initJList(wikisList);

    progrLangsList = new JList(new DefaultListModel());
    progrLangsList = mainframe.initJList(progrLangsList);

    osystemList = new JList(new DefaultListModel());
    osystemList = mainframe.initJList(osystemList);

    mirrorsList = new JList(new DefaultListModel());
    mirrorsList = mainframe.initJList(mirrorsList);

    bugdbList = new JList(new DefaultListModel());
    bugdbList = mainframe.initJList(bugdbList);
  }

  private JPanel fillInUserProfileData2() {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.setBackground(Color.white);
    JPanel vertic = null;

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);

    JScrollPane listScrollPane = new JScrollPane(sameAsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    addSameAsButton = new JButton("Add >>");
    addSameAsButton = mainframe.initButton(addSameAsButton, this, mainframe.buttonDimension,
        "Add the selected sameAs URI to the list on the right.");
    removeSameAsButton = new JButton("Remove <<");
    removeSameAsButton = mainframe.initButton(removeSameAsButton, this, mainframe.buttonDimension,
        "Remove the selected sameAs URI from the list on the right.");
    vertic.add(mainframe.addJListFillingComponent(sameAsLabel, sameAsText, addSameAsButton,
        removeSameAsButton, sameAsListLabel, listScrollPane, ""));
    vertic.add(Box.createVerticalStrut(3));

    listScrollPane = new JScrollPane(seeAlsoList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    addSeeAlsoButton = new JButton("Add >>");
    addSeeAlsoButton = mainframe.initButton(addSeeAlsoButton, this, mainframe.buttonDimension,
        "Add the selected seeAlso URI to the list on the right.");
    removeSeeAlsoButton = new JButton("Remove <<");
    removeSeeAlsoButton = mainframe.initButton(removeSeeAlsoButton, this,
        mainframe.buttonDimension, "Remove the selected seeAlso URI from the list on the right.");
    vertic.add(mainframe.addJListFillingComponent(seeAlsoLabel, seeAlsoText, addSeeAlsoButton,
        removeSeeAlsoButton, seeAlsoListLabel, listScrollPane, ""));
    vertic.add(Box.createVerticalStrut(3));

    listScrollPane = new JScrollPane(membersRoleList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addMembersRoleButton == null) {
      addMembersRoleButton = new JButton("Add >>");
      addMembersRoleButton = mainframe.initButton(addMembersRoleButton, this,
          mainframe.buttonDimension, "Add the inserted members/role " + "to the list");
    }
    if (removeMembersRoleButton == null) {
      removeMembersRoleButton = new JButton("Remove <<");
      removeMembersRoleButton = mainframe.initButton(removeMembersRoleButton, this,
          mainframe.buttonDimension, "Remove the inserted members/role " + "to the list");
    }
    membersRoleValueText = new JTextField(10);
    membersRoleValueText = mainframe.initTextField(membersRoleValueText, "", true);
    membersRoleListLabel = new JLabel();
    membersRoleListLabel = mainframe.initLabel(membersRoleListLabel, "Role - list of members:");
    membersRoleValueLabel = new JLabel();
    membersRoleValueLabel = mainframe.initLabel(membersRoleValueLabel, "Member's email:");
    rolesComboLabel = new JLabel();
    rolesComboLabel = mainframe.initLabel(rolesComboLabel, "Roles:");
    rolesCombo = new JComboBox(HackystatConstants.ROLES_LIST);
    rolesCombo = mainframe.initComboBox(rolesCombo, this);
    vertic.add(mainframe.addJListFillingComponent(membersRoleValueLabel, membersRoleValueText,
        addMembersRoleButton, removeMembersRoleButton, membersRoleListLabel, listScrollPane, null,
        rolesComboLabel, rolesCombo));
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    listScrollPane = new JScrollPane(devPhasesList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addDevPhaseButton == null) {
      addDevPhaseButton = new JButton("Add >>");
      addDevPhaseButton = mainframe.initButton(addDevPhaseButton, this, mainframe.buttonDimension,
          "Add the inserted development phase " + "to the list");
    }
    if (removeDevPhaseButton == null) {
      removeDevPhaseButton = new JButton("Remove <<");
      removeDevPhaseButton = mainframe.initButton(removeDevPhaseButton, this,
          mainframe.buttonDimension, "Remove the inserted development phase " + "to the " + "list");
    }
    devPhaseValueText = new JTextField(10);
    devPhaseValueText = mainframe.initTextField(devPhaseValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(devPhaseValueLabel, devPhaseValueText,
        addDevPhaseButton, removeDevPhaseButton, devPhaseLabel, listScrollPane, ""));

    listScrollPane = new JScrollPane(tagsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addTagsButton == null) {
      addTagsButton = new JButton("Add >>");
      addTagsButton = mainframe.initButton(addTagsButton, this, mainframe.buttonDimension,
          "Add the inserted tag to the " + "list");
    }
    if (removeTagsButton == null) {
      removeTagsButton = new JButton("Remove <<");
      removeTagsButton = mainframe.initButton(removeTagsButton, this, mainframe.buttonDimension,
          "Remove the inserted tag " + "to the " + "list");
    }
    tagsValueText = new JTextField(10);
    tagsValueText = mainframe.initTextField(tagsValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(tagsValueLabel, tagsValueText, addTagsButton,
        removeTagsButton, tagsLabel, listScrollPane, ""));
    vertic.add(Box.createVerticalStrut(3));
    listScrollPane = new JScrollPane(toolsList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (addToolsButton == null) {
      addToolsButton = new JButton("Add >>");
      addToolsButton = mainframe.initButton(addToolsButton, this, mainframe.buttonDimension,
          "Add the inserted tool to the " + "list");
    }
    if (removeToolsButton == null) {
      removeToolsButton = new JButton("Remove <<");
      removeToolsButton = mainframe.initButton(removeToolsButton, this, mainframe.buttonDimension,
          "Remove the inserted tool " + "to the " + "list");
    }
    toolsValueText = new JTextField(10);
    toolsValueText = mainframe.initTextField(toolsValueText, "", true);
    vertic.add(mainframe.addJListFillingComponent(toolsValueLabel, toolsValueText, addToolsButton,
        removeToolsButton, toolsLabel, listScrollPane, ""));
    horiz.add(vertic);
    return horiz;
  }

  private JPanel fillInUserProfileData1() {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.setBackground(Color.white);
    JPanel vertic = null;

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(visibilityLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(visibilityText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(projnameLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(projnameText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(ownerLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(ownerText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repAnonLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(repAnonText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(repText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repWebLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(repWebText);
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(startDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(startDateText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(endDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(endDateText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(modifiedDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(modifiedDateText);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(descriptionLabel);
    vertic.add(Box.createVerticalStrut(1));
    descriptionArea = new JTextArea();
    descriptionArea = mainframe.initTextArea(descriptionArea, false);
    JScrollPane listScrollPane = new JScrollPane(descriptionArea);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    horiz.add(vertic);

    return horiz;
  }

  private JPanel fillInProjectSkills() {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.setBackground(Color.white);
    JPanel vertic = null;

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(skillsLabel);
    vertic.add(Box.createVerticalStrut(1));
    skillsCombo = new JComboBox(HackystatConstants.SKILLS_LIST);
    mainframe.initComboBox(skillsCombo, this);
    vertic.add(skillsCombo);
    horiz.add(vertic);
    horiz.add(Box.createHorizontalStrut(5));
    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    greaterThanCheckBox = new JCheckBox(SparqlFilter.OP_GREATER_THAN);
    greaterThanCheckBox = mainframe.initCheckBox(greaterThanCheckBox, this, "Greater than", true,
        true);
    vertic.add(greaterThanCheckBox);
    vertic.add(Box.createVerticalStrut(1));
    equalsToCheckBox = new JCheckBox(SparqlFilter.OP_EQUALS_TO);
    equalsToCheckBox = mainframe.initCheckBox(equalsToCheckBox, this, "Equals to", true, false);
    vertic.add(equalsToCheckBox);
    vertic.add(Box.createVerticalStrut(1));
    lessThanCheckBox = new JCheckBox(SparqlFilter.OP_LESS_THAN);
    lessThanCheckBox = mainframe.initCheckBox(lessThanCheckBox, this, "Less than", true, false);
    vertic.add(lessThanCheckBox);
    horiz.add(vertic);
    horiz.add(Box.createHorizontalStrut(5));

    addFilterButton = new JButton("Add >>");
    addFilterButton = mainframe.initButton(addFilterButton, this, mainframe.buttonDimension,
        "Add the selected filter value to the list on the right.");
    removeFilterButton = new JButton("Remove <<");
    removeFilterButton = mainframe.initButton(removeFilterButton, this, mainframe.buttonDimension,
        "Remove the selected filter value from the list on the right.");
    DefaultListModel skillsListModel = new DefaultListModel();
    skillsValueList = new JList(skillsListModel);
    skillsValueList = mainframe.initJList(skillsValueList);
    JScrollPane listScrollPane = new JScrollPane(skillsValueList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    horiz.add(mainframe.addJListFillingComponent(filterValueLabel, filterValueText,
        addFilterButton, removeFilterButton, skillsListLabel, listScrollPane, ""));
    Border loweredetched = BorderFactory.createLineBorder(Color.blue);
    TitledBorder title = BorderFactory.createTitledBorder(loweredetched, "Quality measures", 0, 0,
        new Font("Dialog", Font.BOLD, 13), Color.BLUE);
    horiz.setBorder(title);
    return horiz;
  }

  private JPanel getActions() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.setBackground(Color.white);
    searchButton = new JButton("Search");
    searchButton = mainframe.initButton(searchButton, this, mainframe.buttonDimension,
        "Start search");
    panel.add(searchButton);
    panel.add(Box.createHorizontalStrut(5));
    cancelButton = new JButton("Cancel");
    cancelButton = mainframe.initButton(cancelButton, this, mainframe.buttonDimension,
        "Reset fields.");
    panel.add(cancelButton);
    return panel;
  }

  private void initLabelHeaders1() {
    if (filterValueLabel == null) {
      filterValueLabel = new JLabel();
      filterValueLabel = mainframe.initLabel(filterValueLabel, "Value:");
    }
    if (descriptionLabel == null) {
      descriptionLabel = new JLabel();
      descriptionLabel = mainframe.initLabel(visibilityLabel, "Description:");
    }

    if (visibilityLabel == null) {
      visibilityLabel = new JLabel();
      visibilityLabel = mainframe.initLabel(visibilityLabel, "Visibility:");
    }

    if (ownerLabel == null) {
      ownerLabel = new JLabel();
      ownerLabel = mainframe.initLabel(ownerLabel, "Owner:");
    }

    if (projnameLabel == null) {
      projnameLabel = new JLabel();
      projnameLabel = mainframe.initLabel(projnameLabel, "Project name:");
    }

    if (endDateLabel == null) {
      endDateLabel = new JLabel();
      endDateLabel = mainframe.initLabel(endDateLabel, "End date:");
    }

    if (modifiedDateLabel == null) {
      modifiedDateLabel = new JLabel();
      modifiedDateLabel = mainframe.initLabel(modifiedDateLabel, "Last modification date:");
    }

    if (repAnonLabel == null) {
      repAnonLabel = new JLabel();
      repAnonLabel = mainframe.initLabel(repAnonLabel, "Anonymous repository:");
    }

    if (repLabel == null) {
      repLabel = new JLabel();
      repLabel = mainframe.initLabel(repLabel, "Repository:");
    }

    if (repWebLabel == null) {
      repWebLabel = new JLabel();
      repWebLabel = mainframe.initLabel(repWebLabel, "Repository " + " Web browser interface:");
    }

    if (startDateLabel == null) {
      startDateLabel = new JLabel();
      startDateLabel = mainframe.initLabel(startDateLabel, "Start date:");
    }

    if (skillsLabel == null) {
      skillsLabel = new JLabel();
      skillsLabel = mainframe.initLabel(skillsLabel, "Quality measures:");
    }

    if (seeAlsoLabel == null) {
      seeAlsoLabel = new JLabel();
      seeAlsoLabel = mainframe.initLabel(seeAlsoLabel, "SeeAlso URI:");
    }

    if (skillsListLabel == null) {
      skillsListLabel = new JLabel();
      skillsListLabel = mainframe.initLabel(skillsListLabel, "List of selected quality measures:");
    }

    if (sameAsLabel == null) {
      sameAsLabel = new JLabel();
      sameAsLabel = mainframe.initLabel(sameAsLabel, "SameAs URI:");
    }

    if (sameAsListLabel == null) {
      sameAsListLabel = new JLabel();
      sameAsListLabel = mainframe.initLabel(sameAsListLabel, "List of selected sameAs URIs:");
    }

    if (seeAlsoListLabel == null) {
      seeAlsoListLabel = new JLabel();
      seeAlsoListLabel = mainframe.initLabel(seeAlsoListLabel, "List of selected seeAlso URIs:");
    }

    if (devPhaseLabel == null) {
      devPhaseLabel = new JLabel();
      devPhaseLabel = mainframe.initLabel(devPhaseLabel, "devPhase URI:");
    }

    if (devPhaseValueLabel == null) {
      devPhaseValueLabel = new JLabel();
      devPhaseValueLabel = mainframe
          .initLabel(devPhaseValueLabel, "List of selected devPhase URI:");
    }

    if (tagsLabel == null) {
      tagsLabel = new JLabel();
      tagsLabel = mainframe.initLabel(tagsLabel, "tags URI:");
    }

    if (tagsValueLabel == null) {
      tagsValueLabel = new JLabel();
      tagsValueLabel = mainframe.initLabel(tagsValueLabel, "List of selected tags URIs:");
    }

    if (toolsLabel == null) {
      toolsLabel = new JLabel();
      toolsLabel = mainframe.initLabel(toolsLabel, "tools URI:");
    }

    if (toolsValueLabel == null) {
      toolsValueLabel = new JLabel();
      toolsValueLabel = mainframe.initLabel(toolsValueLabel, "List of selected tools URI:");
    }

    if (invitatesLabel == null) {
      invitatesLabel = new JLabel();
      invitatesLabel = mainframe.initLabel(invitatesLabel, "invitates URI:");
    }

    if (invitatesValueLabel == null) {
      invitatesValueLabel = new JLabel();
      invitatesValueLabel = mainframe.initLabel(invitatesValueLabel,
          "List of selected invitates URI:");
    }

    if (membersLabel == null) {
      membersLabel = new JLabel();
      membersLabel = mainframe.initLabel(membersLabel, "members URI:");
    }

    if (membersValueLabel == null) {
      membersValueLabel = new JLabel();
      membersValueLabel = mainframe.initLabel(membersValueLabel, "List of selected members URI:");
    }

    if (spectatorsLabel == null) {
      spectatorsLabel = new JLabel();
      spectatorsLabel = mainframe.initLabel(spectatorsLabel, "spectators URI:");
    }

    if (spectatorsValueLabel == null) {
      spectatorsValueLabel = new JLabel();
      spectatorsValueLabel = mainframe.initLabel(spectatorsValueLabel,
          "List of selected spectators URI:");
    }

    if (wikisLabel == null) {
      wikisLabel = new JLabel();
      wikisLabel = mainframe.initLabel(wikisLabel, "wikis URI:");
    }

    if (wikisValueLabel == null) {
      wikisValueLabel = new JLabel();
      wikisValueLabel = mainframe.initLabel(wikisValueLabel, "List of selected wikis URI:");
    }

    if (progrLangsLabel == null) {
      progrLangsLabel = new JLabel();
      progrLangsLabel = mainframe.initLabel(progrLangsLabel, "progrLangs URI:");
    }

    if (progrLangsValueLabel == null) {
      progrLangsValueLabel = new JLabel();
      progrLangsValueLabel = mainframe.initLabel(progrLangsValueLabel,
          "List of selected progrLangs URI:");
    }

    if (mirrorsLabel == null) {
      mirrorsLabel = new JLabel();
      mirrorsLabel = mainframe.initLabel(mirrorsLabel, "mirrors URI:");
    }

    if (mirrorsValueLabel == null) {
      mirrorsValueLabel = new JLabel();
      mirrorsValueLabel = mainframe.initLabel(mirrorsValueLabel, "List of selected mirrors URI:");
    }

    if (bugdbLabel == null) {
      bugdbLabel = new JLabel();
      bugdbLabel = mainframe.initLabel(bugdbLabel, "bugdb URI:");
    }

    if (bugdbValueLabel == null) {
      bugdbValueLabel = new JLabel();
      bugdbValueLabel = mainframe.initLabel(bugdbValueLabel, "List of selected bugdb URI:");
    }

    if (osystemValueLabel == null) {
      osystemValueLabel = new JLabel();
      osystemValueLabel = mainframe.initLabel(osystemLabel, "Operating system:");
    }

    if (osystemLabel == null) {
      osystemLabel = new JLabel();
      osystemLabel = mainframe.initLabel(osystemLabel, "List of selected osystem URI:");
    }
  }

  @Override
  public void itemStateChanged(ItemEvent e) {
    Object obj = e.getSource();
    System.out.println("in itemeventttt!");
    if (e.getStateChange() == ItemEvent.SELECTED) {
      if (obj.equals(greaterThanCheckBox)) {
        if (lessThanCheckBox.isSelected()) {
          lessThanCheckBox.setSelected(false);
        }
        if (equalsToCheckBox.isSelected()) {
          equalsToCheckBox.setSelected(false);
        }
      }
      else if (obj.equals(lessThanCheckBox)) {
        if (greaterThanCheckBox.isSelected()) {
          greaterThanCheckBox.setSelected(false);
        }
        if (equalsToCheckBox.isSelected()) {
          equalsToCheckBox.setSelected(false);
        }
      }
      else if (obj.equals(equalsToCheckBox)) {
        if (lessThanCheckBox.isSelected()) {
          lessThanCheckBox.setSelected(false);
        }
        if (greaterThanCheckBox.isSelected()) {
          greaterThanCheckBox.setSelected(false);
        }
      }
    }

  }

  @Override
  public void actionPerformed(ActionEvent e) {
    Object obj = e.getSource();
    String text = null;
    if (obj.equals(addSeeAlsoButton)) {
      text = seeAlsoText.getText();
      if (!text.startsWith("http://")) {
        JOptionPane.showMessageDialog(this, "The inserted URI must begin with 'http://'",
            "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
        return;
      }
      DefaultListModel model = ((DefaultListModel) seeAlsoList.getModel());
      model.add(model.getSize(), text);
      seeAlsoList.repaint();
    }
    else if (obj.equals(addSameAsButton)) {
      text = sameAsText.getText();
      if (!text.startsWith("http://")) {
        JOptionPane.showMessageDialog(this, "The inserted URI must begin with 'http://'",
            "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
        return;
      }
      DefaultListModel model = ((DefaultListModel) sameAsList.getModel());
      model.add(model.getSize(), text);
      sameAsList.repaint();
    }
    else if (obj.equals(addFilterButton)) {
      text = filterValueText.getText();
      if (text.contains(" ")) {
        JOptionPane.showMessageDialog(this,
            "The value inserted as a filter on skills can't contain spaces.",
            "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
        return;
      }
      text = text.replace(".", ",");
      String comparator = greaterThanCheckBox.isSelected() ? greaterThanCheckBox.getText()
          : (lessThanCheckBox.isSelected() ? lessThanCheckBox.getText() : (equalsToCheckBox
              .isSelected() ? equalsToCheckBox.getText() : null));
      if (comparator == null) {
        JOptionPane.showMessageDialog(this, "You must select one of the available check boxes.",
            "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
        return;
      }
      if (!text.contains(",") && !text.contains(".")) {
        text += ",0";
      }
      String filterSkill = skillsCombo.getSelectedItem().toString() + " " + comparator + " " + text;
      DefaultListModel model = ((DefaultListModel) skillsValueList.getModel());
      model.add(model.getSize(), filterSkill);
      skillsValueList.repaint();
    }
    else if (obj.equals(removeSeeAlsoButton)) {
      if (!seeAlsoList.isSelectionEmpty()) {
        int index = seeAlsoList.getSelectedIndex();
        if (index != -1) {
          ((DefaultListModel) seeAlsoList.getModel()).remove(index);
        }
        seeAlsoList.repaint();
      }
    }
    else if (obj.equals(removeSameAsButton)) {
      if (!sameAsList.isSelectionEmpty()) {
        int index = sameAsList.getSelectedIndex();
        if (index != -1) {
          ((DefaultListModel) sameAsList.getModel()).remove(index);
        }
        sameAsList.repaint();
      }
    }
    else if (obj.equals(removeFilterButton)) {
      if (!skillsValueList.isSelectionEmpty()) {
        int index = skillsValueList.getSelectedIndex();
        if (index != -1) {
          ((DefaultListModel) skillsValueList.getModel()).remove(index);
        }
        skillsValueList.repaint();
      }
    }
    else if (obj.equals(addMembersRoleButton)) {
      String role = membersRoleValueText.getText(), elem = null, member = membersRoleValueText
          .getText();
      if (member != null && !member.trim().equals("")) {
        DefaultListModel model = (DefaultListModel) membersRoleList.getModel();
        boolean found = false;
        for (int i = 0; i < model.size() && !found; i++) {
          elem = String.valueOf(model.get(i));
          if (elem.contains(role)) {
            elem += "," + membersRoleValueText.getText();
            found = true;
          }
        }
        if (!found) {
          text = role + " - " + member;
          model.addElement(text);
        }
        membersRoleList.repaint();
      }
    }
    else if (obj.equals(removeMembersRoleButton)) {
      JList jlist = membersRoleList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addTagsButton)) {
      text = tagsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = tagsList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeTagsButton)) {
      JList jlist = tagsList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addToolsButton)) {
      text = toolsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = toolsList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeToolsButton)) {
      JList jlist = toolsList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addDevPhaseButton)) {
      text = devPhaseValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = devPhasesList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeDevPhaseButton)) {
      JList jlist = devPhasesList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addWikisButton)) {
      text = wikisValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = wikisList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeWikisButton)) {
      JList jlist = wikisList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addMirrorsButton)) {
      text = mirrorsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = mirrorsList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeMirrorsButton)) {
      JList jlist = mirrorsList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addBugdbButton)) {
      text = bugdbValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = bugdbList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeBugdbButton)) {
      JList jlist = bugdbList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addProgrLangsButton)) {
      text = progrLangsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = tagsList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeProgrLangsButton)) {
      JList jlist = progrLangsList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addOsystemButton)) {
      text = osystemValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = osystemList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeOsystemButton)) {
      JList jlist = osystemList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addMemebersButton)) {
      text = membersValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = membersList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeMemebersButton)) {
      JList jlist = membersList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addSpectatorsButton)) {
      text = spectatorsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = spectatorsList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeSpectatorsButton)) {
      JList jlist = spectatorsList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(addInvitatesButton)) {
      text = invitatesValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = invitatesList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (obj.equals(removeInvitatesButton)) {
      JList jlist = invitatesList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (obj.equals(cancelButton)) {
      refresh(true);
    }
    else if (obj.equals(searchButton)) {
      org.hackystat.linkedservicedata.sparql.ProjectQuery pq = new org.hackystat.linkedservicedata.sparql.ProjectQuery();
      String projectname = projnameText.getText();
      String owner = ownerText.getText();
      String start = startDateText.getText();
      String end = endDateText.getText();
      String modified = modifiedDateText.getText();
      String description = descriptionArea.getText();
      String[] progrlangs = mainframe.getJListContent(progrLangsList.getModel());
      String[] osystems = mainframe.getJListContent(osystemList.getModel());
      String[] bugdatabases = mainframe.getJListContent(bugdbList.getModel());
      String[] mirrors = mainframe.getJListContent(mirrorsList.getModel());
      String repwebinterface = repWebText.getText();
      String repanon = repAnonText.getText();
      String rep = repText.getText();
      String[] wikis = mainframe.getJListContent(wikisList.getModel());
      String[] tags = mainframe.getJListContent(tagsList.getModel());
      String[] tools = mainframe.getJListContent(toolsList.getModel());
      String[] devPhases = mainframe.getJListContent(devPhasesList.getModel());
      String[] invitations = mainframe.getJListContent(invitatesList.getModel());
      String[] spectators = mainframe.getJListContent(spectatorsList.getModel());
      String[] members = mainframe.getJListContent(membersList.getModel());
      String[] seeAlso = mainframe.getJListContent(seeAlsoList.getModel());
      String[] sameAs = mainframe.getJListContent(sameAsList.getModel());
      HashMap<OntProperty, String[]> usersRoles = getMemberRolesMap((DefaultListModel) membersRoleList
          .getModel());
      LinkedList<SparqlFilter> sparqlFiltersList = mainframe.getSparqlFilters(skillsValueList
          .getModel());
      String empty = "";
      if (sparqlFiltersList != null && !sparqlFiltersList.isEmpty()) {
        pq.filtersList = sparqlFiltersList;
      }
      if (bugdatabases != null && bugdatabases.length != 0) {
        pq.bugdatabases = bugdatabases;
      }
      if (description != null && !description.trim().equals(empty)) {
        pq.description = description;
      }
      if (devPhases != null && devPhases.length != 0) {
        pq.devPhases = devPhases;
      }
      if (end != null && !end.trim().equals(empty)) {
        pq.end = end;
      }
      if (invitations != null && invitations.length != 0) {
        pq.invitations = invitations;
      }
      if (members != null && members.length != 0) {
        pq.members = members;
      }
      if (mirrors != null && mirrors.length != 0) {
        pq.mirrors = mirrors;
      }
      if (modified != null && !modified.trim().equals(empty)) {
        pq.modified = modified;
      }
      if (osystems != null && osystems.length != 0) {
        pq.osystems = osystems;
      }
      if (owner != null && !owner.trim().equals(empty)) {
        pq.owner = owner;
      }
      if (progrlangs != null && progrlangs.length != 0) {
        pq.progrlangs = progrlangs;
      }
      if (projectname != null && !projectname.trim().equals(empty)) {
        pq.projectname = projectname;
      }
      if (rep != null && !rep.trim().equals(empty)) {
        pq.rep = rep;
      }
      if (repanon != null && !repanon.trim().equals(empty)) {
        pq.repanon = repanon;
      }
      if (repwebinterface != null && !repwebinterface.trim().equals(empty)) {
        pq.repwebinterface = repwebinterface;
      }
      if (sameAs != null && sameAs.length != 0) {
        pq.sameAs = sameAs;
      }
      if (seeAlso != null && seeAlso.length != 0) {
        pq.seeAlso = seeAlso;
      }
      if (spectators != null && spectators.length != 0) {
        pq.spectators = spectators;
      }
      if (start != null && !start.trim().equals(empty)) {
        pq.start = start;
      }
      if (tags != null && tags.length != 0) {
        pq.tags = tags;
      }
      if (tools != null && tools.length != 0) {
        pq.tools = tools;
      }
      if (usersRoles != null && !usersRoles.isEmpty()) {
        pq.usersRoles = usersRoles;
      }
      if (wikis != null && wikis.length != 0) {
        pq.wikis = wikis;
      }
      try {
        String queryResult = mainframe.getLiSeDClient().searchForProjects(pq);
        queryResult = mainframe.getURIList(queryResult);
        mainframe.displayQueryResults(queryResult);
      }
      catch (Exception e1) {
        JOptionPane.showMessageDialog(this, e1.getMessage(), "Hackystat - Error Message",
            JOptionPane.ERROR_MESSAGE);
        e1.printStackTrace();
        return;
      }
    }
  }

  private HashMap<OntProperty, String[]> getMemberRolesMap(DefaultListModel model) {
    HashMap<OntProperty, String[]> ret = new HashMap<OntProperty, String[]>();
    String elem = null, members = null;
    String[] split = null;
    OntProperty ontp = null;
    for (int i = 0; i < model.size(); i++) {
      elem = String.valueOf(model.get(i));
      split = elem.split(" - ");
      members = split[1];
      ontp = getRoleOntProperty(split[0]);
      if (ontp != null) {
        ret.put(ontp, members.split(","));
      }
    }
    return ret;
  }

  private OntProperty getRoleOntProperty(String role) {
    if (role.equals(HackystatConstants.ROLES_LIST[0])) {
      return DoapVocab.DEVELOPER;
    }
    else if (role.equals(HackystatConstants.ROLES_LIST[0])) {
      return DoapVocab.MAINTAINER;
    }
    else if (role.equals(HackystatConstants.ROLES_LIST[0])) {
      return DoapVocab.TESTER;
    }
    else if (role.equals(HackystatConstants.ROLES_LIST[0])) {
      return DoapVocab.TRANSLATOR;
    }
    else if (role.equals(HackystatConstants.ROLES_LIST[0])) {
      return DoapVocab.HELPER;
    }
    return null;
  }
}
